<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var lengthOfLongestSubstring = function (s) {
            if (s.length <= 1) return s.length
            var myMap = new Map()
            myMap.set(s[0], 0)

            var left = 0
            var right = 1
            var len = 1
            while (right < s.length) {
                if (myMap.has(s[right])&&myMap.get(s[right]) >= left) {
                    left = myMap.get(s[right]) + 1
                    myMap.set(s[right], right)
                    right++
                } else {
                    myMap.set(s[right], right)
                    right++
                    len = Math.max(len, right - left)
                }
            }
            return len 
        };
        console.log(lengthOfLongestSubstring('tmmzuxt'))
    </script>
</body>

</html>